From 981b39ef0b89646e7fa8ba22f974e70ed2162a99 Mon Sep 17 00:00:00 2001 From: "cl349@freefall.cl.cam.ac.uk" Date: Fri, 12 Nov 2004 15:06:36 +0000 Subject: [PATCH] bitkeeper revision 1.1159.172.3 (4194d17cHAKS_aZt34dj741AVg4MNQ) Split irq_serial_getc out of serial_getc, irq_serial_getc can be called from interrupt handlers. --- xen/drivers/char/console.c | 15 +++++++++++++++ xen/drivers/char/serial.c | 39 +++++++++++++++++++++++--------------- xen/include/xen/console.h | 4 ++++ xen/include/xen/serial.h | 1 + 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index 7a706b2e2c..cb57740996 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -436,6 +436,21 @@ void console_force_lock(void) spin_lock(&console_lock); } +void console_putc(char c) +{ + serial_putc(sercon_handle, c); +} + +int console_getc(void) +{ + return serial_getc(sercon_handle); +} + +int irq_console_getc(void) +{ + return irq_serial_getc(sercon_handle); +} + /* * ************************************************************** diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 8ca8972175..bdd1995f52 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -416,13 +416,10 @@ static int byte_matches(int handle, unsigned char *pc) return 0; } -unsigned char serial_getc(int handle) +unsigned char irq_serial_getc(int handle) { uart_t *uart = &com[handle & SERHND_IDX]; unsigned char c; - unsigned long flags; - - spin_lock_irqsave(&uart->lock, flags); while ( uart->rxbufp != uart->rxbufc ) { @@ -431,16 +428,6 @@ unsigned char serial_getc(int handle) goto out; } - disable_irq(uart->irq); - - /* disable_irq() may have raced execution of uart_rx(). */ - while ( uart->rxbufp != uart->rxbufc ) - { - c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)]; - if ( byte_matches(handle, &c) ) - goto enable_and_out; - } - /* We now wait for the UART to receive a suitable character. */ do { while ( (inb(uart->io_base + LSR) & LSR_DR) == 0 ) @@ -449,7 +436,29 @@ unsigned char serial_getc(int handle) } while ( !byte_matches(handle, &c) ); - enable_and_out: + out: + return c; +} + +unsigned char serial_getc(int handle) +{ + uart_t *uart = &com[handle & SERHND_IDX]; + unsigned char c; + unsigned long flags; + + spin_lock_irqsave(&uart->lock, flags); + + while ( uart->rxbufp != uart->rxbufc ) + { + c = uart->rxbuf[MASK_RXBUF_IDX(uart->rxbufc++)]; + if ( byte_matches(handle, &c) ) + goto out; + } + + disable_irq(uart->irq); + + c = irq_serial_getc(handle); + enable_irq(uart->irq); out: spin_unlock_irqrestore(&uart->lock, flags); diff --git a/xen/include/xen/console.h b/xen/include/xen/console.h index 628eb044d4..abcb2fa1d8 100644 --- a/xen/include/xen/console.h +++ b/xen/include/xen/console.h @@ -22,4 +22,8 @@ void console_endboot(int disable_vga); void console_force_unlock(void); void console_force_lock(void); +void console_putc(char c); +int console_getc(void); +int irq_console_getc(void); + #endif diff --git a/xen/include/xen/serial.h b/xen/include/xen/serial.h index c0ffebbbd9..b805405093 100644 --- a/xen/include/xen/serial.h +++ b/xen/include/xen/serial.h @@ -41,6 +41,7 @@ void serial_puts(int handle, const unsigned char *s); * will not return until a character is available. It can safely be * called with interrupts disabled. */ +unsigned char irq_serial_getc(int handle); unsigned char serial_getc(int handle); void serial_force_unlock(int handle); -- 2.30.2